package com.jrj.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jrj.dao.LoginDao;
import com.jrj.domain.User;
import com.jrj.mapping.UserMapping;

/**
 *@author Adminstrator
 *@version createTime��2011-11-9 ����06:03:42
 */
@Service
public class LoginService extends BaseService{

	
	
	@Autowired
	private LoginDao loginDao;
	
	
	public User getUserByName(String name){
		User user = loginDao.getUserByName(name);
		return user;
	}
	
	/**
	 * add user
	 * @return
	 */
	public Integer addUser(User user){
		loginDao.addUser(user);
		return null;
	}
	
	/**
	 * add user
	 * @return
	 */
	public List<User> getUser(){
		List<User> list = loginDao.getUserList();
		return list;
	}
	
	public User getUser(String name){
		String sql = "select * from user where name like '%"+name+"%'";
		System.out.println(sql);
		User user = null;
		try {
			System.out.println(this.jdbcTemplate);
			List<User> listUser = this.jdbcTemplate.query(sql, new UserMapping());
			if(null!=listUser){
				user = listUser.get(0);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return user;
	}
	
	
}
